package mathive.client.panels;

import mathive.client.PanelHandler;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class HomePanel {
	
	private VerticalPanel mainPanel = new VerticalPanel();
	private HorizontalPanel hPanel = new HorizontalPanel();
	private Image gamesButton = new Image();
	private Image testsButton = new Image();
	private Image contactButton = new Image();
	private HTML title;
	private HTML info;
	
	public HomePanel(){

		Window.addResizeHandler(new WindowResizeHandler());
		
		gamesButton.setUrl("gamesLogo.png");
		testsButton.setUrl("testsLogo.png");
		contactButton.setUrl("contactLogo.png");
		gamesButton.setStyleName("menuImage");
		testsButton.setStyleName("menuImage");
		contactButton.setStyleName("menuImage");

		title = new HTML("<h1>Mathive Playground</h1>");
		info = new HTML("<p>Welcome to Mathive Playground!<br>" +
				"Here you can find different math games to play around with.<br>" +
				"Check out the tests section to challenge yourself.</p>");
		
		hPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		hPanel.setSpacing(20);
		hPanel.add(gamesButton);
		hPanel.add(testsButton);
		hPanel.add(contactButton);
		
		mainPanel.add(title);
		mainPanel.add(hPanel);
		mainPanel.add(info);
		

		// Listen for mouse events on the minemap button.
		gamesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showGames();
			}
		});
		

		// Listen for mouse events on the minemap button.
		testsButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showTests();
			}
		});
		

		// Listen for mouse events on the minemap button.
		contactButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showContact();
			}
		});
		
		update();
		
	}
	
	public Widget getPanel(){
		return mainPanel;
	}
	
	private void update(){
		gamesButton.setSize("auto", "" + Window.getClientHeight() * 0.2);
		testsButton.setSize("auto", "" + Window.getClientHeight() * 0.2);
		contactButton.setSize("auto", "" + Window.getClientHeight() * 0.2);
	}
	
	private class WindowResizeHandler implements ResizeHandler {
		@Override
		public void onResize(ResizeEvent event) {
			update();
		}
	}
}
